<template>
	<view class="group-madal u-flex u-col-center u-row-center" @click.stop.prevent="">
		<view class="madal">
			<image src="../../static/images/icon_close@2x.png" mode="" @click="hide" class="close-icon"></image>
			<view class="u-font-32">
				{{!vuex_is_farmer?"升级":"续约"}}农场主
			</view>
			<view class="u-font-60 u-margin-top-60">
				需15000个欢嘻豆
			</view>
			<view class="u-font-32 color-999999 u-margin-top-26">
				{{!vuex_is_farmer?"升级":"续约"}}农场主即可开团得福利
			</view>
			<view class="u-flex u-col-center u-row-around u-margin-top-60" style="width: 100%;">
				<u-button :custom-style="customStyle" hover-class="none" @click="hide">我再想想</u-button>
				<u-button :custom-style="customStyle2" hover-class="none" @click="farmer">{{!vuex_is_farmer?"立即升级":"立即续约"}}</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "group-madal",
		data() {
			return {
				customStyle: {
					width: "200rpx",
					height: "70rpx",
					background: "rgba(189,189,189,1)",
					border: "4rpx solid rgba(149,149,149,1)",
					borderRadius: "20rpx",
				},
				customStyle2: {
					width: "200rpx",
					height: "70rpx",
					background: "rgba(245,179,64,1)",
					border: "4rpx solid rgba(204,126,43,1)",
					borderRadius: "20rpx",
					color: "#FFFFFF"
				}
			};
		},
		methods: {
			hide() {
				this.$emit('toggleGroupMadal')
			},
			farmer(){
				uni.showLoading({
					mask: true,
					title: "请稍等..."
				})
				if(!this.vuex_is_farmer){
					this.applyFarmer()
					return false
				}
				this.renewFarmer()
			},
			applyFarmer() {
				let params = {
					timestamp: Number(new Date())
				}
				this.$u.api.getApplyFarmer(params).then(res => {
					uni.hideLoading()
					this.$u.toast(res.errmsg)
					if (res.errno == '000') {
						this.$u.vuex('vuex_is_farmer', 1)
						this.$emit('toggleGroupMadal')
					}
				}).catch(err => {
					console.log(err)
				})
			},
			renewFarmer() {
				let params = {
					timestamp: Number(new Date())
				}
				this.$u.api.getRenewFarmer(params).then(res => {
					uni.hideLoading()
					this.$u.toast(res.errmsg)
					if (res.errno == '000') {
						this.$u.vuex('vuex_is_farmer', 1)
						this.$emit('toggleGroupMadal')
					}
				}).catch(err => {
					console.log(err)
				})
			}
		}
	}
</script>

<style>
	.group-madal {
		width: 100vw;
		height: 100vh;
		background: rgba(0, 0, 0, .5);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 1006;
	}

	.madal {
		width: 580rpx;
		height: 520rpx;
		background: rgba(255, 255, 255, 1);
		border: 4rpx solid rgba(167, 92, 26, 1);
		border-radius: 20rpx;
		position: relative;
		overflow: hidden;
		text-align: center;
		padding-top: 52rpx;
		box-sizing: border-box;
	}

	.close-icon {
		width: 148rpx;
		height: 140rpx;
		position: absolute;
		right: -68rpx;
		top: -60rpx;
	}
</style>
